package com.shujia.wyh.mysql_jdbc;

import com.shujia.wyh.mysql_jdbc.utils.MySQLTool;
import redis.clients.jedis.Jedis;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/*
    JDBC实现模糊查询
 */
public class JDBCDemo6 {
    public static void main(String[] args) throws Exception {
        //获取数据连接对象
        Connection conn = MySQLTool.getConnection();

        //获取数据库操作预编译对象
        PreparedStatement preparedStatement = conn.prepareStatement("select username,password from login where username like ?");

        //给占位符设置值
//        preparedStatement.setString(1, "张%");
        preparedStatement.setString(1, "%怀%");

        //执行sql语句
        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            String name = resultSet.getString(1);
            String password = resultSet.getString(2);

            System.out.println(name + "---" + password);
        }
    }
}
